using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Cobalt75.GreyMatter;
using Cobalt75.GreyMatter.MySql;
using Cobalt75.GreyMatter.FirebirdSql;
using Lois.Types;

namespace Cobalt75.GreyMatter.Tester.UnitTests
{
    [TestFixture]
    public class TestAll
    {
        [TestFixtureSetUp]
        public void Init()
        {
            Console.WriteLine("Create MySql GMC");
            MySqlGMCommunicator mysqlgmc = new MySqlGMCommunicator("gmtest");
            string fBirdPath = @"C:\gmunittest.fdb";

            Console.WriteLine("Create FirebirdSql GMC");
            if (File.Exists(fBirdPath))
            {
                File.Delete(fBirdPath);
            }
            FirebirdSqlGMCommunicator firebgmc = new FirebirdSqlGMCommunicator("C:\\", "gmunittest");

            communicators = new GMCommunicator[] { mysqlgmc, firebgmc };
            AppDomain.CurrentDomain.Load("Cobalt75.GreyMatter.TesterTypes");
        }

        [TestFixtureTearDown]
        public void Dispose()
        {
            Console.WriteLine("Dispose");
            foreach (GMCommunicator gmc in communicators)
            {
                Console.WriteLine(gmc.GetType().Name);
                gmc.Dispose();

            }
        }


        GMCommunicator[] communicators;
        [Test]
        public void CreateDBSchema()
        {
            Console.WriteLine("CreateDBSchema");
            foreach (GMCommunicator gmc in communicators)
            {
                Console.WriteLine(gmc.GetType().Name);
                gmc.CreateDBSchemaAndReport();

            }
        }

        [Test]
        public void CreateSomeDummyData()
        {

            foreach (GMCommunicator gmc in communicators)
            {
                Style s = new Style(gmc);
                s.Code = "My ManfName";
                gmc.CreateDB(s);
                

            }
            Style[] styles = new Style[] {
                communicators[0].SelectFromId<Style>(1),
                communicators[1].SelectFromId<Style>(1)
            
            };

            Assert.AreEqual(styles[0], styles[1]);
            Assert.AreEqual(styles[0].Code, styles[1].Code);
        }
    }
}
